home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / NEW_TECH / TRSHCN.ZIP / NTRASH11.C < prev    next >
C/C++ Source or Header  |  1993-09-18  |  9KB  |  250 lines

  1.  
  2. /******************************************************************************
  3. *                                                                             *
  4. *          NTrash Version 1.1 - File Deletion utility for Windows NT          *
  5. *                                                                             *
  6. *                   by Mark Gamber - August 3, 1992                           *
  7. *                                                                             *
  8. *                    Compiled for July 1992 WinNT release.                    *
  9. *                                                                             *
  10. ******************************************************************************/
  11.  
  12.  
  13. #include "windows.h"
  14. #include "ntrash11.h"
  15.  
  16.  
  17. HANDLE hInst;                                      //  Global Variables go here
  18. HWND MainWin;
  19. BOOL StayOnTop = TRUE;
  20. char *IniSection = "NTRASH";
  21. char *IniFile = "NTRASH.INI";
  22.  
  23.  
  24. int PASCAL WinMain( HANDLE hInstance, HANDLE hPrev, LPSTR lpCmd, int nCmdShow )
  25. {
  26.    WNDCLASS wc;
  27.    HWND hWnd;
  28.    MSG msg;
  29.    UINT Xpos, Ypos;
  30.  
  31.    if( hPrev )
  32.       return( FALSE );
  33.  
  34.    wc.style = CS_DBLCLKS;                              //  Accept double-clicks
  35.    wc.lpfnWndProc = MainWndProc;
  36.    wc.cbClsExtra = 0;
  37.    wc.cbWndExtra = 0;
  38.    wc.hInstance = hInstance;
  39.    wc.hIcon = LoadIcon( hInstance, "MainI" );
  40.    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
  41.    wc.hbrBackground = GetStockObject( LTGRAY_BRUSH );
  42.    wc.lpszMenuName = NULL;
  43.    wc.lpszClassName = "CTEST";
  44.  
  45.    if( ! RegisterClass( &wc ) )              // If class doesn't register, exit
  46.       return( FALSE );
  47.  
  48.    hInst = hInstance;
  49.  
  50.    Xpos = GetPrivateProfileInt( IniSection, "XPOS", 0, IniFile );
  51.    Ypos = GetPrivateProfileInt( IniSection, "YPOS", 0, IniFile );
  52.    StayOnTop = GetPrivateProfileInt( IniSection, "SOT", 1, IniFile );
  53.  
  54.    hWnd = CreateWindowEx( WS_EX_ACCEPTFILES | WS_EX_TOPMOST,
  55.                           "CTEST",
  56.                           (LPSTR)"Test",
  57.                           WS_VISIBLE | WS_CLIPSIBLINGS | WS_POPUP,
  58.                           Xpos, Ypos,
  59.                           48, 48,
  60.                           NULL,
  61.                           NULL,
  62.                           hInstance,
  63.                           NULL );
  64.  
  65.    if( ! hWnd )
  66.       return( FALSE );                        // If create failed, exit program
  67.  
  68.    MainWin = hWnd;
  69.    ShowWindow( hWnd, SW_SHOWNORMAL );                         // Display window
  70.    UpdateWindow( hWnd );
  71.  
  72.    if( StayOnTop )
  73.       SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
  74.    else
  75.       SetWindowPos( hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
  76.  
  77.    while( GetMessage( &msg, 0, 0, 0 ) )                      // Do message loop
  78.    {
  79.       TranslateMessage( &msg );             // This is hauntingly familiar, no?
  80.       DispatchMessage( &msg );
  81.    }
  82.    return( msg.wParam );
  83. }
  84.  
  85.  
  86.  
  87.                         //  Main window - This is the one that accepts files...
  88.  
  89. long APIENTRY MainWndProc( HWND hWnd, UINT msg, UINT wParam, LONG lParam )
  90. {
  91.    switch( msg )
  92.    {
  93.       case WM_LBUTTONDOWN:             // If left button pressed, move window
  94.       {
  95.          PostMessage( hWnd, WM_SYSCOMMAND, 0xF012, 0x00110017 );
  96.          break;
  97.       }
  98.  
  99.       case WM_RBUTTONDOWN:                        // If right button pressed...
  100.       {                     // Note - no more of this MakeProcInstance nonsense
  101.          DialogBox( hInst, "MAINDLG", hWnd, MainDlgProc );
  102.          break;
  103.       }
  104.  
  105.       case WM_LBUTTONDBLCLK:                     // Quit on double-click
  106.       {
  107.          RECT Rect;
  108.          char str[ 8 ];
  109.  
  110.          GetWindowRect( hWnd, &Rect );
  111.          wsprintf( str, "%d", Rect.left );
  112.          WritePrivateProfileString( IniSection, "XPOS", str, IniFile );
  113.          wsprintf( str, "%d", Rect.top );
  114.          WritePrivateProfileString( IniSection, "YPOS", str, IniFile );
  115.          wsprintf( str, "%d", StayOnTop );
  116.          WritePrivateProfileString( IniSection, "SOT", str, IniFile );
  117.          PostQuitMessage( 0 );
  118.          break;
  119.       }
  120.  
  121.       case WM_DROPFILES:          // When files are dropped on the window...
  122.       {
  123.          WORD Files, Count, len;
  124.          char Filename[ 128 ];
  125.          char FullPath[ 192 ];
  126.          char TempPath[ 64 ];
  127.          HDC hDC;
  128.          HDC mDC;
  129.          HBITMAP hBmp;
  130.                                                  // Get number of files dropped
  131.          Files = DragQueryFile( (HDROP)wParam, -1, Filename, 128 );
  132.          if( ! Files )
  133.          {
  134.             DragFinish( (HDROP)wParam );        // If none, tell SHELL and exit
  135.             return( TRUE );
  136.          }                                         // Search for a TMP variable
  137.  
  138.          if( ! GetEnvironmentVariable( "tmp", TempPath, 64 ) )
  139.          {
  140.             MessageBox( hWnd, "TMP system variable is not set!\n    Unable to Continue",
  141.                                 "Error", MB_OK | MB_ICONSTOP );
  142.             DragFinish( (HDROP)wParam );
  143.             return( TRUE );                   //  If no TMP, tell user and exit
  144.          }
  145.  
  146.          hDC = GetDC( hWnd );
  147.          mDC = CreateCompatibleDC( hDC );          //  Draw can with the lid up
  148.          hBmp = LoadBitmap( hInst, "TUP" );
  149.          SelectObject( mDC, hBmp );
  150.          BitBlt( hDC, 0, 0, 48, 48, mDC, 0, 0, SRCCOPY );
  151.          DeleteDC( mDC );
  152.          DeleteObject( hBmp );
  153.          ReleaseDC( hWnd, hDC );
  154.  
  155.          for( Count = 0; Count < Files; Count++ )     // Get every file dropped
  156.          {
  157.             DragQueryFile( (HDROP)wParam, Count, Filename, 128 );
  158.  
  159.             lstrcpy( FullPath, TempPath );                  // Begin dest. path
  160.                 lstrcat( FullPath, "\\" );                         // Add backslash
  161.  
  162.                 len = lstrlen( Filename );           // Get length of filename passed
  163.                 while( Filename[ len ] != '\\' )      // Search for first backslash
  164.                     --len;                 // i.e. Find start of filename
  165.  
  166.                 lstrcat( FullPath, Filename + len + 1 );    // Add filename to path
  167.             CopyFile( Filename, FullPath, FALSE );       // Copy to destination
  168.             DeleteFile( Filename );
  169.          }
  170.          DragFinish( (HDROP)wParam );                  // Tell SHELL we're done
  171.          InvalidateRect( hWnd, NULL, FALSE );          // Repaint with lid down
  172.          return( TRUE );
  173.       }
  174.  
  175.       case WM_PAINT:
  176.       {
  177.          PAINTSTRUCT ps;
  178.          HDC hDC;
  179.          HDC mDC;
  180.          HBITMAP hBmp;
  181.  
  182.          hDC = BeginPaint( hWnd, &ps );         // Blasts out can with lid down
  183.          mDC = CreateCompatibleDC( hDC );
  184.          hBmp = LoadBitmap( hInst, "TDOWN" );
  185.          SelectObject( mDC, hBmp );
  186.          BitBlt( hDC, 0, 0, 48, 48, mDC, 0, 0, SRCCOPY );
  187.          DeleteDC( mDC );
  188.          DeleteObject( hBmp );
  189.          EndPaint( hWnd, &ps );
  190.          break;
  191.       }
  192.  
  193.       case WM_DESTROY:
  194.          PostQuitMessage( 0 );
  195.          break;
  196.  
  197.       default:
  198.          return( DefWindowProc( hWnd, msg, wParam, lParam ) );
  199.    }
  200.    return( FALSE );
  201. }
  202.  
  203.  
  204.              // Settings dialog box....and purges TMP directory
  205.  
  206. BOOL APIENTRY MainDlgProc( HWND hDlg, UINT msg, UINT wParam, LONG lParam )
  207. {
  208.    switch( msg )
  209.    {
  210.       case WM_INITDIALOG:                                       // Set checkbox
  211.          CheckDlgButton( hDlg, IDM_STAYONTOP, StayOnTop );
  212.          return( TRUE );
  213.  
  214.       case WM_COMMAND:
  215.          if( wParam == IDCANCEL )                    // When Exit it pressed...
  216.          {                                        // Save 'Stay On Top' setting
  217.             StayOnTop = IsDlgButtonChecked( hDlg, IDM_STAYONTOP );
  218.  
  219.                                          // If checked, mark window accordingly
  220.             if( StayOnTop )
  221.                SetWindowPos( GetParent( hDlg ), HWND_TOPMOST, 0, 0, 0, 0,
  222.                              SWP_NOMOVE | SWP_NOSIZE );
  223.             else
  224.                SetWindowPos( GetParent( hDlg ), HWND_NOTOPMOST, 0, 0, 0, 0,
  225.                              SWP_NOMOVE | SWP_NOSIZE );
  226.  
  227.             EndDialog( hDlg, TRUE );
  228.             r